{% extends "base.html" %}

{% block breadcrumb_current %}
    
{% endblock %}

{% block content %}
    {% if messages %}
        {% for message in messages %}
            <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                {{ message }}
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </div>
        {% endfor %}
    {% endif %}

    <!-- 主内容区 -->
    <div class="container-fluid mt-3">
        <div class="row">
            <!-- 左侧导航栏 -->
            <div class="col-md-2 col-lg-2 p-0 bg-white shadow-sm" id="sidebar">
                {% if request.user.is_superuser %}
                    <div class="list-group rounded-0">
                        <a class="list-group-item list-group-item-action active"
                           style="background-color: #417690; color: #eff4bc !important;">
                            <i class="fa-solid fa-user-secret me-2"></i>超级用户
                        </a>
                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'supercompany_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>地市管理
                            </a>
                            <a href="{% url 'supercompany_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2"></i>增加
                            </a>
                        </div>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'superdepartment_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>部门管理
                            </a>
                            <a href="{% url 'superdepartment_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2"></i>增加
                            </a>
                        </div>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'superuser_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>人员管理
                            </a>
                            <a href="{% url 'superuser_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2"></i>增加
                            </a>
                        </div>
                    </div>
                {% endif %}

                {% if request.user.is_manager %}
                    <div class="list-group rounded-0">
                        <a class="list-group-item list-group-item-action active"
                           style="background-color: #417690; color: #eff4bc !important;">
                            <i class="fa-solid fa-user-group me-2"></i>公共参数
                        </a>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'user_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>用户管理
                            </a>
                            <a href="{% url 'user_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2" style="color: #417690;"></i>增加
                            </a>
                        </div>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'department_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>县区管理
                            </a>
                            <a href="{% url 'department_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2" style="color: #417690;"></i>增加
                            </a>
                        </div>
                    </div>

                    <div class="list-group rounded-0">
                        <a class="list-group-item list-group-item-action active"
                           style="background-color: #417690; color: #eff4bc !important;">
                            <i class="fa-solid fa-user-group me-2"></i>物料参数
                        </a>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'warehouse_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>仓库管理
                            </a>
                            <a href="{% url 'warehouse_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2" style="color: #417690;"></i>增加
                            </a>
                        </div>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'materialtype_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>物料类别
                            </a>
                            <a href="{% url 'materialtype_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2" style="color: #417690;"></i>增加
                            </a>
                        </div>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'material_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>物料名称
                            </a>
                            <a href="{% url 'material_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2" style="color: #417690;"></i>增加
                            </a>
                        </div>
                    </div>

                    <div class="list-group rounded-0">
                        <a class="list-group-item list-group-item-action active"
                           style="background-color: #417690; color: #eff4bc !important;">
                            <i class="fa-solid fa-key me-2"></i>设备参数
                        </a>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'place_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>设备位置
                            </a>
                            <a href="{% url 'place_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2" style="color: #417690;"></i>增加
                            </a>
                        </div>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'technology_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>技术类别
                            </a>
                            <a href="{% url 'technology_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2" style="color: #417690;"></i>增加
                            </a>
                        </div>

                        <div class="list-group-item list-group-item-action fs-6 d-flex" style="color: #417690;">
                            <a href="{% url 'factory_list' %}" class="text-decoration-none me-2"
                               style="color: #417690;">
                                <i class="fa-solid fa-pen-to-square me-2" style="color: #417690;"></i>设备厂家
                            </a>
                            <a href="{% url 'factory_add' %}" class="text-decoration-none ms-auto"
                               style="color: #417690;">
                                <i class="fa fa-plus me-2" style="color: #417690;"></i>增加
                            </a>
                        </div>
                    </div>

                    <div class="list-group rounded-0">
                        <a class="list-group-item list-group-item-action active"
                           style="background-color: #417690; color: #eff4bc !important;">
                            <i class="fa-regular fa-file me-2"></i>导出Excel
                        </a>

                        <a href="{% url 'export_inventory' %}"
                           class="list-group-item list-group-item-action fs-6"
                           style="color: #417690;"
                           onclick="return confirm('确定要导出物料清单吗？');">
                            <i class="fa-solid fa-file-export me-2"></i>物料清单
                        </a>

                        <a href="{% url 'export_inventoryrecord' %}"
                           class="list-group-item list-group-item-action fs-6"
                           style="color: #417690;"
                           onclick="return confirm('确定要导出物料出入库历史数据吗？');">
                            <i class="fa-solid fa-file-export me-2"></i>物料历史
                        </a>

                        <a href="{% url 'export_device' %}"
                           class="list-group-item list-group-item-action fs-6"
                           style="color: #417690;"
                           onclick="return confirm('确定要导出设备清单吗？');">
                            <i class="fa-solid fa-file-export me-2"></i>设备清单
                        </a>

                        <a href="{% url 'export_devicehistory' %}"
                           class="list-group-item list-group-item-action fs-6"
                           style="color: #417690;"
                           onclick="return confirm('确定要导出设备调整历史数据吗？');">
                            <i class="fa-solid fa-file-export me-2"></i>设备历史
                        </a>
                    </div>
                {% endif %}
                
                {% if user.is_inventoryoperator %}
                <div class="list-group rounded-0">
                    <a class="list-group-item list-group-item-action active"
                       style="background-color: #417690; color: #eff4bc !important;">
                        <i class="fa-solid fa-warehouse me-2"></i>维护物料
                    </a>
                    <a href="{% url 'inventory_list' %}" class="list-group-item list-group-item-action fs-6"
                       style="color: #417690;">
                        <i class="fa fa-tasks me-2"></i>库存物料清单
                    </a>
                    <a href="{% url 'inventory_record_list' %}" class="list-group-item list-group-item-action fs-6"
                       style="color: #417690;">
                        <i class="fa fa-tasks me-2"></i>物料使用记录
                    </a>
                </div>
                {% endif %}
                
                {% if user.is_deviceoperator %}
                <div class="list-group rounded-0">
                    <a class="list-group-item list-group-item-action active"
                       style="background-color: #417690; color: #eff4bc !important;">
                        <i class="fa-solid fa-pager me-2"></i>接入设备
                    </a>
                    <a href="{% url 'device_list' %}" class="list-group-item list-group-item-action fs-6"
                       style="color: #417690;">
                        <i class="fa fa-tasks me-2"></i>设备使用情况
                    </a>
                    <a href="{% url 'devicehistory_list' %}" class="list-group-item list-group-item-action fs-6"
                       style="color: #417690;">
                        <i class="fa fa-tasks me-2"></i>设备调整记录
                    </a>
                </div>
                {% endif %}
                <div class="list-group rounded-0">
                    <a href="{% url 'help_page' %}"
                       class="list-group-item list-group-item-action active"
                       target="_blank"
                       style="background-color: #417690; color: #eff4bc !important;">
                        <i class="fa-solid fa-book-open me-2"></i>操作手册
                    </a>
                </div>
            </div>

            <!-- 右侧内容区 -->
            <div class="col-lg-10 p-1">
                <!-- 展开/收缩按钮 -->
                <button class="btn btn-secondary btn-sm mb-0" id="toggleSidebar"
                        style="background-color: #417690;">
                    <i class="fa-solid fa-ellipsis"></i>
                </button>

                <div class="bg-light p-3 shadow-sm" style="margin-top: 15px;">
                    <h5 class="mb-4" style="color: #417690;">
                        <i class="fa-solid fa-user-shield"></i> 账号安全
                    </h5>
                    <p style="color: #417690;">您上次登录是{{ last_login }}</p>
                    <p style="color: #417690;">如果不是您本人登录请联系管理员</p>
                </div>

                <div class="bg-light p-3 shadow-sm">
                    <h5 class="mb-4" style="color: #417690;">
                        <i class="fa-regular fa-bell me-2"></i> 审批待办
                    </h5>
                    {% if request.user.is_approver %}
                        {% if request.user.is_inventoryoperator %}
                            <p>
                                <a href="{% url 'pending_inventory_list' %}" class="text-decoration-none"
                                   style="color: #417690;">
                                    您有{{ inventoryapproval_count }}条物料出入库审批待办。
                                </a>
                            </p>
                        {% endif %}
                        {% if request.user.is_deviceoperator %}
                            <p>
                                <a href="{% url 'pending_devicehistory' %}" class="text-decoration-none"
                                   style="color: #417690;">
                                    您有{{ deviceapproval_count }}条设备调整审批待办。
                                </a>
                            </p>
                        {% endif %}
                    {% else %}
                        <p>您没有维护物料和接入设备的审批权限</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            const sidebar = document.getElementById('sidebar');
            const toggleBtn = document.getElementById('toggleSidebar');

            // 切换侧边栏显示状态
            toggleBtn.addEventListener('click', function () {
                sidebar.classList.toggle('d-none');
                sidebar.classList.toggle('col-md-3');
                sidebar.classList.toggle('col-lg-2');
            });
        });
    </script>
{% endblock %}